﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cit.CDE.Net.Module;
using Cit.CDE.Net.Service.ModuleFactory;
using Module;
using Cit.CDE.Net.Service;
using Cit.CDE.Net.Module.Commons;
using cde.SystemCommon;
using UserControl;
using System.Text;

public partial class main_test_Canzhaoddl : UserControl.CommonPage
{
    private CDEEntityManager em;

    private CDESearchCriteria sc;
   
    private CDEEntity m_entity;

    private List<CDEEntity> list;

    private string chkID;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        em = CDEEMFactory.getEMByFullName("WEB.P_TEST");


        if (!Page.IsPostBack)
        {
            if (chkID != "" && chkID != null)
            {
                sc = new CDESearchCriteria(em);

                sc.addCondition("ID", chkID);

                List<CDEEntity> listEntity = CDEService.LoadEntities(em, sc);

                if (listEntity.Count < 1)
                {
                    m_entity = CDEEMServiceFactory.getEMService(em).CreateEntity();
                    m_entity.Operation = CDEDataOperation.INSERT;
                }
                else
                {

                    m_entity = listEntity[0];
                    m_entity.Operation = CDEDataOperation.UPDATE;

                }
            }
            else
            {
                m_entity = CDEEMServiceFactory.getEMService(em).CreateEntity();
            }

            this.setControls(m_entity, Resources.ResourceErrMsg.ResourceManager);

            Session["contract_entity"] = m_entity;
        }
        else
        {
            m_entity = (CDEEntity)Session["contract_entity"];
        } 
        this.setEntityFromRequest(m_entity, Request.Params);
    }
}
